<template>
  <div>
    <van-popup 
      v-model="registerShow" 
      round
      :close-on-click-overlay="false"
      @click-overlay="registerClose">
      <div class="register_detail">
        <h3>账号详情</h3>
        <p>
          <span>APP账号：</span>
          <span  id="copy_text" :data-clipboard-text="userInfo.username">{{userInfo.username}}</span>
        </p>
        <p>
          <span>手机号：</span>
          <span>{{userInfo.mobile}}</span>
        </p>
        <p>
          <span>渠道ID：</span>
          <span>{{userInfo.tgid}}</span>
        </p>
        <p>
          <span>注册日期：</span>
          <span>{{userInfo.regtime | fnDateTime}}</span>
        </p>
        <p>
          <span>最后登录时间：</span>
          <span>{{userInfo.logintime | fnDateTime}}</span>
        </p>
        <p>
          <span>最后登录IP地址：</span>
          <span>{{userInfo.loginip}}</span>
        </p>
        <p>
          <span>注册游戏：</span>
          <span>{{userInfo.lastlogin_gamename}}</span>
        </p>
        <p>
          <span>绑定设备信息：</span>
          <span>
            <i v-if="userInfo.login_device_id === '1'">Android</i>
            <i v-else-if="userInfo.login_device_id === '2'">IOS</i>
          </span>
        </p>
        <van-button 
          round 
          class="copy_btn" 
          @click="copyClick"
          id="copy_text"
          :data-clipboard-text="userInfo.username">
          复制账号</van-button>
      </div>
    </van-popup>
  </div>
</template>

<script>
import Clipboard from 'clipboard'
import jutils from 'jutils-src'
import {Toast} from 'vant'
  export default {
    props: {
      registerShow: {
        type: Boolean,
        default: false,
      },
      userInfo: {
        type: Object,
        default: {},
      },
    },
    methods: {
      registerClose() {
        this.$emit('register-close')
      },
      copyClick() {
        let clipboard = new Clipboard('#copy_text')
        clipboard.on('success', e => {
          Toast('已复制到剪切板')
          clipboard.destroy() // 释放内存
        })
        clipboard.on('error', e => {
          // 不支持复制
          Toast('该浏览器不支持复制')
          clipboard.destroy() // 释放内存
        })
        this.$emit('register-close')
      }
    },
    filters: {
    fnDateTime: function(date) {
      // YYYY-MM-DD HH:ii:ss
      return jutils.formatDate(new Date(date*1000),"YYYY-MM-DD HH:ii:ss")
    }
  }
  }
</script>

<style scoped>
.register_detail {
  box-sizing: border-box;
  padding: 40px;
  width: 580px;
  height: 900px;
  background: #fff;
}

.register_detail h3 {
  text-align: center;
  font-size: 30px;
  color: #333;
  font-weight: 600;
  margin-bottom: 40px;
}

.register_detail p {
  font-size: 24px;
  line-height: 80px;
}

.register_detail p span:first-child {
  color: #666;
}

.register_detail p span:last-child {
  color: #333;
}

.copy_btn {
  width: 236px;
  height: 75px;
  margin: 30px 132px 0;
  font-size: 26px;
  color: #fff;
  border: 0;
  background: #2f41eb;
  font-weight: 600;
}
</style>